//package design.templateMethod.helingang.main;
//import design.templateMethod.helingang.MaintenanceHandler;
//import design.templateMethod.helingang.imlClass.NewMaintenance;
//import design.templateMethod.helingang.car.Car;
//import design.templateMethod.helingang.car.CarState;
//import java.util.concurrent.*;
//import	java.util.concurrent.locks.Lock;
//import java.util.concurrent.locks.ReentrantLock;
//
//
///**
// * @program: LearningDemo
// * @author: Lenny
// * @create: 2019-08-19 22:08
// **/
//public class Main {
//    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        /*
//        默认
//        *  Maintenance maintenance=new TraditionalMaintenance();
//        maintenance.maintenance();
//        * */
//
//
//       //  ThreadPoolWay();
//        SingleThreadWay();
//
//
//    }
//
//    private static void SingleThreadWay() {
//        Lock lock = new ReentrantLock();
//        Car car=new Car(1, CarState.RESERVATION);
//        MaintenanceHandler handlerNew = new NewMaintenance(car,lock);
//        handlerNew.setNextHandler(handlerNew);
//        ((NewMaintenance) handlerNew).setThread(Thread.currentThread());
//        handlerNew.check();
//        if (NewMaintenance.TIME_OUT_FLAG){
//            System.out.println("重试次数上限为"+NewMaintenance.TRY_LIMIT_TIME+",已达上限");
//            return;
//        }else {
//            handlerNew.wash();
//        }
//    }
//
//
//    private static void ThreadPoolWay() {
//        Lock lock = new ReentrantLock();
//        Car car=new Car(1, CarState.RESERVATION);
//        MaintenanceHandler handlerNew = new NewMaintenance(car,lock);
//
//        ExecutorService threadPool=new ThreadPoolExecutor(
//                1,
//                2,
//                1L,
//                TimeUnit.SECONDS,
//                new LinkedBlockingQueue<>(1),
//                Executors.defaultThreadFactory(),
//                new ThreadPoolExecutor.DiscardOldestPolicy());
//
//        try {
//            for (int i = 0; i <= 5; i++) {
//                threadPool.execute(()->{
//                    ((NewMaintenance) handlerNew).setThread(Thread.currentThread());
//                    handlerNew.setNextHandler(handlerNew);
//                    handlerNew.check();
//                    if (NewMaintenance.TIME_OUT_FLAG){
//                        System.out.println("重试次数上限为"+NewMaintenance.TRY_LIMIT_TIME+",已达上限");
//                        return;
//                    }else {
//                        handlerNew.wash();
//                    }
//                    handlerNew.wash();
//                });
//            }
//        }catch (Exception e)
//        {
//            e.printStackTrace();
//        }finally {
//            threadPool.shutdown();
//        }
//        System.out.println(car.toString());
//    }
//}
